<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <title>首页 - 文章列表</title>
    <style>
        /* 全局样式 */
        body {
            font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
            background-color: #f9f9f9;
            margin: 0;
            padding: 0;
            color: #333;
            line-height: 1.6;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 15px;
        }

        /* 导航栏样式 */
        .navbar {
            background-color: #ffffff;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            margin-bottom: 30px;
            padding: 15px 0;
        }

        .navbar-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .navbar-brand {
            font-size: 24px;
            font-weight: 600;
            color: #3a7d44;
            text-decoration: none;
        }

        .navbar-nav {
            display: flex;
            align-items: center;
        }

        .nav-item {
            margin-left: 15px;
        }

        .nav-link {
            color: #555;
            font-size: 15px;
            text-decoration: none;
            font-weight: 500;
        }

        .nav-link:hover {
            color: #4caf50;
        }

        .btn-group {
            display: flex;
            align-items: center;
        }

        .btn-group .btn {
            margin-left: 10px;
        }

        /* 按钮样式 */
        .btn {
            font-weight: 500;
            transition: all 0.3s ease;
            border-radius: 20px;
            padding: 8px 16px;
            font-size: 14px;
        }

        .btn-primary {
            background-color: #4caf50;
            border-color: #4caf50;
            color: white;
        }

        .btn-primary:hover {
            background-color: #388e3c;
            border-color: #388e3c;
        }

        .btn-outline-primary {
            color: #4caf50;
            border-color: #4caf50;
        }

        .btn-outline-primary:hover {
            background-color: #4caf50;
            color: white;
        }

        .btn-success {
            background-color: #4caf50;
            border-color: #4caf50;
            color: white;
        }

        .btn-success:hover {
            background-color: #388e3c;
            border-color: #388e3c;
        }

        .btn-warning {
            background-color: #ffc107;
            border-color: #ffc107;
            color: #212529;
        }

        .btn-warning:hover {
            background-color: #e0a800;
            border-color: #e0a800;
        }

        .btn-info {
            background-color: #17a2b8;
            border-color: #17a2b8;
            color: white;
        }

        .btn-info:hover {
            background-color: #138496;
            border-color: #138496;
        }

        .btn-danger {
            background-color: #dc3545;
            border-color: #dc3545;
            color: white;
        }

        .btn-danger:hover {
            background-color: #bd2130;
            border-color: #bd2130;
        }

        /* 标题样式 */
        .main-title {
            text-align: center;
            margin-bottom: 30px;
        }

        .main-title h2 {
            font-size: 32px;
            color: #3a7d44;
            font-weight: 600;
            margin-bottom: 15px;
            position: relative;
            display: inline-block;
        }

        .main-title h2:after {
            content: '';
            position: absolute;
            width: 60px;
            height: 3px;
            background-color: #4caf50;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
        }

        /* 分类按钮样式 */
        .category-buttons {
            display: flex;
            justify-content: center;
            flex-wrap: wrap;
            gap: 10px;
            margin-bottom: 30px;
        }

        .category-buttons .btn {
            font-size: 14px;
            padding: 8px 16px;
            background-color: #e8f5e9;
            border: 1px solid #c8e6c9;
            color: #3a7d44;
        }

        .category-buttons .btn:hover {
            background-color: #c8e6c9;
            color: #2e7d32;
        }

        /* 文章卡片样式 */
        .row {
            display: flex;
            flex-wrap: wrap;
            margin: 0 -10px;
        }

        .col {
            flex: 0 0 calc(50% - 20px);
            margin: 10px;
            box-sizing: border-box;
        }

        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
            border: none;
            background-color: white;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            margin-bottom: 20px;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
        }

        .card-body {
            padding: 20px;
        }

        .article-title {
            font-size: 1.5rem;
            font-weight: 600;
            color: #333;
            margin-bottom: 10px;
        }

        .article-meta {
            color: #777;
            font-size: 0.9rem;
            margin-bottom: 10px;
        }

        .card-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 20px;
            background-color: #f8f9fa;
            border-top: none;
        }

        /* 空状态提示 */
        .alert {
            text-align: center;
            font-size: 1.1rem;
            margin-top: 40px;
            padding: 20px;
            border-radius: 10px;
            background-color: #e3f2fd;
            color: #1976d2;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .col {
                flex: 0 0 100%;
            }

            .navbar-container {
                flex-direction: column;
                align-items: flex-start;
            }

            .navbar-nav {
                margin-top: 15px;
                flex-wrap: wrap;
            }

            .btn-group .btn {
                margin-bottom: 10px;
            }
        }
    </style>
</head>
<body>

<div class="content container">

    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="container-fluid navbar-container">
            <a class="navbar-brand" href="#">个人博客系统</a>
            <div class="navbar-nav">
                <span sec:authorize="isAuthenticated()">
                    <div class="btn-group">
                        <span>欢迎, <span sec:authentication="name"></span>!</span>
                        <a href="/user/logout" class="btn btn-sm btn-outline-danger">退出</a>
                        <a href="/user/info" class="btn btn-sm btn-outline-secondary">个人中心</a>
                        <a href="/article/add" class="btn btn-sm btn-outline-success">新建博客</a>
                        <a href="/admin/index" class="btn btn-sm btn-outline-warning">管理员界面</a>
                        <a href="/email" class="btn btn-sm btn-outline-info">邮箱</a>
                    </div>
                </span>
                <span sec:authorize="!isAuthenticated()">
                     <a href="/user/info" class="btn btn-sm btn-outline-secondary">个人中心</a>
                        <a href="/article/add" class="btn btn-sm btn-outline-success">新建博客</a>
                        <a href="/admin/index" class="btn btn-sm btn-outline-warning">管理员界面</a>
                        <a href="/email" class="btn btn-sm btn-outline-info">邮箱</a>
                    <a href="/user/login" class="btn btn-sm btn-primary">登录</a>
                </span>
            </div>
        </div>
    </nav>

    <!-- 标题 -->
    <div class="main-title">
        <h2 class="text-center mb-5 fw-bold text-dark">热门文章</h2>
    </div>
    <div class="category-buttons">
        <a class="btn btn-sm btn-outline-secondary">文章分类</a>
        <div th:each="category : ${categories}">
            <a th:href="@{/user/index/{id}(id=${category.id})}"
               class="btn btn-sm btn-outline-secondary"
               th:text="${category.name}">
                分类名称
            </a>
        </div>
    </div>

    <!-- 文章列表 -->
    <div class="row">

        <div class="col" th:each="article : ${articles}">
            <div class="card h-100 shadow-sm">
                <div class="card-body">
                    <h5 class="card-title article-title" th:text="${article.title}">文章标题</h5>
                    <p class="card-text text-truncate" th:text="${#strings.abbreviate(article.content, 100)}">文章内容摘要...</p>
                </div>
                <div class="card-footer">
                    <small class="text-muted article-meta">
                        作者：[[${article.username}]] |
                        分类：<span th:text="${article.categoryId == 1 ? '技术' : (article.categoryId == 2 ? '生活' : '未知')}"></span> |
                        阅读量：[[${article.viewCount}]]
                    </small>
                    <a th:href="@{/article/{id}(id=${article.id})}" class="btn btn-sm btn-outline-primary">查看详情</a>
                </div>
            </div>
        </div>

        <!-- 无文章提示 -->
        <div class="col-12 alert alert-info mt-4" th:if="${#lists.isEmpty(articles)}">
            暂无文章。
        </div>

    </div>

</div>

<!-- Bootstrap JS -->
<script th:src="@{/js/bootstrap.bundle.min.js}" src="../../static/js/bootstrap.bundle.min.js"></script>

</body>
</html>